package com.yoga.admin.api.web;

import com.yoga.admin.api.annotation.LoginUser;
import com.yoga.common.appexception.AppErrorCodeEnum;
import com.yoga.common.appexception.AppException;
import com.yoga.common.appexception.YogaResult;
import com.yoga.common.bo.YogaAdminBO;
import com.yoga.common.bo.YogaShopBO;
import com.yoga.common.page.PageBO;
import com.yoga.common.qto.YogaShopQTO;
import com.yoga.manager.admin.AdminYogaShopManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by hdx on 2020/10/20.
 */
@RestController
@RequestMapping("${basePath}")
public class AdminYogaShopController {

    @Resource
    private AdminYogaShopManager yogaShopManager;

    @PostMapping("/shop/addData")
    public YogaResult<YogaShopBO> addData(@LoginUser YogaAdminBO adminBO, @RequestBody YogaShopBO yogaShopBO) throws AppException {
        if (yogaShopBO == null) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_NULL);
        }
        yogaShopBO.setYogaAdminId(adminBO.getYogaAdminId());

        YogaShopBO result = yogaShopManager.addData(yogaShopBO);

        return new YogaResult<>(result);
    }

    @PostMapping("/shop/updateData")
    public YogaResult<Boolean> updateData(@LoginUser YogaAdminBO adminBO, @RequestBody YogaShopBO yogaShopBO) throws AppException {
        Boolean result = yogaShopManager.updateData(yogaShopBO);

        return new YogaResult<>(result);
    }

    @GetMapping("/shop/deleteData")
    public YogaResult<Boolean> deleteData(@LoginUser YogaAdminBO adminBO, Long yogaShopId) throws AppException {
        Boolean result = yogaShopManager.deleteData(yogaShopId);

        return new YogaResult<>(result);
    }

    @PostMapping("/shop/findForPage")
    public YogaResult<PageBO<YogaShopBO>> findForPage(@LoginUser YogaAdminBO adminBO, @RequestBody YogaShopQTO yogaShopQTO) throws AppException {
        if (yogaShopQTO == null) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_NULL);
        }
        yogaShopQTO.setYogaAdminId(adminBO.getYogaAdminId());
        PageBO<YogaShopBO> result = yogaShopManager.findForPage(yogaShopQTO);

        return new YogaResult<>(result);
    }
}
